//
//  DDLogin.m
//  MyClouds
//
//  Created by sarah doo on 13-8-11.
//  Copyright (c) 2013年 sarah doo. All rights reserved.
//

#import "DDLogin.h"
#import "DDCommentDic.h"
@implementation DDLogin

@synthesize token;

- (id)initWithData:(NSData *)data {
    self = [super init];
    if (self) {
        entity = data;
    }
    return self;
}


-(id)initWithTokenData:(NSData *)tokenData{
    self = [super init];
    [self setCmd:CloudCmd_Login];
    NSRange range;
    range.location = HEADER_LENGTH;
    range.length = TOKEN_LENGTH;
    [entity replaceBytesInRange:range withBytes:[tokenData bytes]];
    int cmdLength = HEADER_LENGTH + TOKEN_LENGTH;
    [self setLength:cmdLength];
    [self setCrc:[self crcs:entity withLength:[entity length]]];
    return self;
}

- (id)initWithToken:(NSString*) token{
    self = [super init];
    [self setCmd:CloudCmd_Login];
    NSData* tokenData = [token dataUsingEncoding:NSASCIIStringEncoding];
    NSData* otherData = [token dataUsingEncoding:NSUnicodeStringEncoding];
    NSRange range;
    range.location = HEADER_LENGTH;
    range.length = TOKEN_LENGTH;
    [entity replaceBytesInRange:range withBytes:[tokenData bytes]];
    int cmdLength = HEADER_LENGTH + TOKEN_LENGTH;
    [self setLength:cmdLength];
    [self setCrc:[self crcs:entity withLength:[entity length]]];
    NSLog(@"final------%@",entity);
    return self;
}


-(id)initWithTokenBytes:(Byte *)tokenBytes{
    self = [super init];
    [self setCmd:CloudCmd_Login];
    NSRange range;
    range.location = HEADER_LENGTH;
    range.length = TOKEN_LENGTH;
    [entity appendBytes:tokenBytes length:16];
    int cmdLength = HEADER_LENGTH + TOKEN_LENGTH;
    [self setLength:cmdLength];
    
    [self setCrc:[self crcs:entity withLength:[entity length]]];
    
    return self;
}



@end
